home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / gencodec / source / writeguifiles.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  22KB  |  867 lines

  1. #include "WriteGUIFiles.h"
  2. #include "MB_protos.h"
  3. #include "MB_pragmas.h"
  4. #include "MB.h"
  5. #include "MB_MUI_Strings.h"
  6. #include "Tools.h"
  7.  
  8. #include <exec/types.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. /* variable types */
  15. static char    *STR_type[] =
  16. {
  17.     "BOOL",
  18.     "int",
  19.     "char *",
  20.     "char *",
  21.     "APTR",
  22.     "",
  23.     "",
  24.     "",
  25.     "APTR",
  26.     "APTR"
  27. };
  28.  
  29. /****************************************************************************************************************/
  30. /*****                                                                                                        *****/
  31. /**                                                WriteParameters                                                **/
  32. /*****                                                                                                        *****/
  33. /****************************************************************************************************************/
  34.  
  35. static void WriteParameters(FILE *file,ULONG varnb,BOOL Notifications)
  36. {
  37.     int   i;
  38.     char  *varname, *typename;
  39.     ULONG type,size;
  40.     BOOL  comma = FALSE;
  41.  
  42.     typename = STR_type[ TYPEVAR_EXTERNAL_PTR - 1 ];
  43.     if (Notifications)
  44.     {
  45.         for(i=0;i<varnb;i++)
  46.         {
  47.             MB_GetVarInfo (i,
  48.                            MUIB_VarType, &type,
  49.                            MUIB_VarName, &varname,
  50.                            MUIB_VarSize, &size,
  51.                            TAG_END
  52.                           );
  53.  
  54.             if (type == TYPEVAR_EXTERNAL_PTR)
  55.             {
  56.                 if (comma)
  57.                      fprintf(file, ", ");
  58.  
  59.                 comma = TRUE;
  60.                 fprintf(file, "%s %s", typename, varname);
  61.             }
  62.         }
  63.     }
  64.     if (!comma)
  65.         fprintf(file, "void");
  66. }
  67.  
  68. /****************************************************************************************************************/
  69. /*****                                                                                                        *****/
  70. /**                                                WriteDeclarations                                                **/
  71. /*****                                                                                                        *****/
  72. /****************************************************************************************************************/
  73.  
  74. static void WriteDeclarations(FILE *file,ULONG varnb,int vartype)
  75. {
  76.     int        i;
  77.     char    *varname;
  78.     ULONG    type, size;
  79.     char    *typename;
  80.     int        nb_ident = 1;
  81.     char    *buffer = NULL;
  82.     char    *buffer2 = NULL;
  83.  
  84.     typename = STR_type[ vartype - 1 ];        /* find the name 'BOOL ...'    */
  85.     for(i=0;i<varnb;i++)
  86.     {
  87.         MB_GetVarInfo (i,
  88.                        MUIB_VarType, &type,
  89.                        MUIB_VarName, &varname,
  90.                        MUIB_VarSize, &size,
  91.                        TAG_END
  92.                        );
  93.  
  94.         if (type == vartype)
  95.         {
  96.             switch(type)
  97.             {
  98.                 case TYPEVAR_TABSTRING:
  99.                     fprintf(file, "\t%s\t%s[%d];\n",
  100.                              typename,
  101.                              varname,
  102.                              size+1
  103.                            );
  104.                     break;
  105.  
  106.                 case TYPEVAR_IDENT:
  107.                     fprintf(file,"#define %s %d\n", varname, nb_ident++);
  108.                     break;
  109.  
  110.                 case TYPEVAR_LOCAL_PTR:
  111.                     if (!buffer)
  112.                     {
  113.                         buffer = AllocMemory(strlen(typename)+strlen(varname)+3,TRUE);
  114.                         sprintf(buffer, "\t%s\t%s", typename, varname);
  115.                     }
  116.                     else
  117.                     {
  118.                         buffer2 = buffer;
  119.                         buffer = AllocMemory(strlen(buffer)+strlen(varname)+3,TRUE);
  120.                         sprintf(buffer,"%s, %s",buffer2,varname);
  121.                         FreeMemory(buffer2);
  122.                     }
  123.                     if (strlen(buffer)>=70)
  124.                     {
  125.                         fprintf(file, "%s;\n", buffer);
  126.                         FreeMemory(buffer);
  127.                         buffer = NULL;
  128.                     }
  129.                     break;
  130.  
  131.                 case TYPEVAR_HOOK:
  132.                     fprintf(file, "\tstatic struct Hook %sHook;\n", varname);
  133.                     break;
  134.  
  135.                 default:
  136.                     fprintf(file, "\t%s\t%s;\n",typename, varname);
  137.                     break;
  138.             }
  139.         }
  140.     }
  141.  
  142.     if (buffer && strlen(buffer)>0)
  143.         fprintf(file, "%s;\n", buffer);
  144.  
  145.     FreeMemory(buffer);
  146. }
  147.  
  148. /****************************************************************************************************************/
  149. /*****                                                                                                        *****/
  150. /**                                            WriteInitialisations                                               **/
  151. /*****                                                                                                        *****/
  152. /****************************************************************************************************************/
  153.  
  154. static void WriteInitialisations(FILE *file,ULONG varnb,int vartype,BOOL Locale,char *GetMBString)
  155. {
  156.     int        i, j;
  157.     ULONG    type, size;
  158.     char    *inits, *name;
  159.     BOOL    enter = FALSE;
  160.  
  161.     for(i=0;i<varnb;i++)
  162.     {
  163.         MB_GetVarInfo(i,
  164.                        MUIB_VarType    , &type,
  165.                        MUIB_VarName    , &name,
  166.                        MUIB_VarSize    , &size,
  167.                        MUIB_VarInitPtr    , &inits,
  168.                        TAG_END
  169.                       );
  170.  
  171.         if (type == vartype)
  172.         {
  173.             enter = TRUE;
  174.             switch(type)
  175.             {
  176.                 case TYPEVAR_TABSTRING:
  177.                     for(j=0;j<size;j++)
  178.                     {
  179.                         if (!Locale)
  180.                              fprintf(file, "\tObjectApp->%s[%d] = \"%s\";\n", name, j, inits);
  181.                         else
  182.                             fprintf(file, "\tObjectApp->%s[%d] = %s(%s);\n", name, j, GetMBString, inits);
  183.                         inits = inits + strlen(inits) + 1;
  184.                     }
  185.                     fprintf(file, "\tObjectApp->%s[%d] = NULL;\n", name, j);
  186.                     break;
  187.  
  188.                 case TYPEVAR_STRING:
  189.                      if (*inits != 0)
  190.                     {
  191.                         if (!Locale)
  192.                              fprintf(file, "\tObjectApp->%s = \"%s\";\n", name, inits);
  193.                         else
  194.                            fprintf(file, "\tObjectApp->%s = %s(%s);\n", name, GetMBString, inits);
  195.                     }
  196.                     else
  197.                         fprintf(file, "\tObjectApp->%s = NULL;\n", name);
  198.                     break;
  199.  
  200.                 case TYPEVAR_HOOK:
  201.                     fprintf(file, "\tInstallHook(&%sHook,%s,ObjectApp);\n", name, name);
  202.                     break;
  203.  
  204.                 default:
  205.                     break;
  206.             }
  207.         }
  208.     }
  209.  
  210.     if (enter)
  211.         fprintf(file, "\n");
  212. }
  213.  
  214. /****************************************************************************************************************/
  215. /*****                                                                                                        *****/
  216. /**                                                WriteCode                                                        **/
  217. /*****                                                                                                        *****/
  218. /****************************************************************************************************************/
  219.  
  220. static void WriteCode(FILE *file,char *GetString,char *GetMBString)
  221. {
  222.     ULONG    type;
  223.     char*    code;
  224.     BOOL    InFunction     = FALSE;
  225.     BOOL    IndentFunction = TRUE ;
  226.     BOOL    obj_function   = FALSE;
  227.     BOOL    InObj          = FALSE;
  228.     int        nb_indent      = 1;
  229.     int        nb_function    = 0;
  230.     int        name;
  231.  
  232.     MB_GetNextCode(&type, &code);
  233.     while(type != -1)
  234.     {
  235.         switch(type)
  236.         {
  237.             case TC_CREATEOBJ:
  238.                 name = atoi(code);
  239.                 fprintf(file, "%s,\n",MUIStrings[name]);
  240.                 nb_indent++;
  241.                 IndentFunction = TRUE;
  242.                 MB_GetNextCode(&type, &code);
  243.                 InObj = TRUE;
  244.                 break;
  245.  
  246.             case TC_ATTRIBUT:
  247.                 Indent(file,nb_indent);
  248.                 name = atoi(code);
  249.                 fprintf(file, "%s, ",MUIStrings[name]);
  250.                 IndentFunction = FALSE;
  251.                 MB_GetNextCode(&type, &code);
  252.                 break;
  253.  
  254.             case TC_END:
  255.                 nb_indent--;
  256.                 InObj = FALSE;
  257.                 Indent(file,nb_indent);
  258.                 name = atoi(code);
  259.                 fprintf(file, "%s",MUIStrings[name]);
  260.                 IndentFunction = TRUE;
  261.                 MB_GetNextCode(&type, &code);
  262.                 fprintf(file, ";\n\n");
  263.                 break;
  264.  
  265.             case TC_MUIARG_OBJFUNCTION:
  266.                 if (IndentFunction)
  267.                     Indent(file,nb_indent);
  268.                 nb_function++;
  269.                 name = atoi(code);
  270.                 fprintf(file, "%s(",MUIStrings[name]);
  271.                 IndentFunction = FALSE;
  272.                 MB_GetNextCode(&type, &code);
  273.                 obj_function = TRUE;
  274.                 InFunction = TRUE;
  275.                 break;
  276.  
  277.             case TC_MUIARG_FUNCTION:
  278.             case TC_FUNCTION:
  279.                 if (IndentFunction)
  280.                     Indent(file,nb_indent);
  281.                 nb_function++;
  282.                 name = atoi(code);
  283.                 fprintf(file, "%s(",MUIStrings[name]);
  284.                 IndentFunction = FALSE;
  285.                 InFunction     = TRUE;
  286.                 MB_GetNextCode(&type, &code);
  287.                 obj_function = FALSE;
  288.                 break;
  289.  
  290.             case TC_OBJFUNCTION:
  291.                 if (IndentFunction)
  292.                     Indent(file,nb_indent);
  293.                 nb_function++;
  294.                 name = atoi(code);
  295.                 fprintf(file, "%s(",MUIStrings[name]);
  296.                 InFunction     = TRUE;
  297.                 IndentFunction = FALSE;
  298.                 MB_GetNextCode(&type,&code);
  299.                 obj_function = TRUE;
  300.                 break;
  301.  
  302.             case TC_STRING:
  303.                 fprintf(file, "\"%s\"",code);
  304.                 MB_GetNextCode(&type, &code);
  305.                 IndentFunction = TRUE;
  306.                 if (InFunction)
  307.                 {
  308.                     if (type  != TC_END_FUNCTION)
  309.                         fprintf(file, ", ");
  310.                     IndentFunction = FALSE;
  311.                 }
  312.                 else
  313.                     fprintf(file, ",\n");
  314.                 break;
  315.  
  316.             case TC_LOCALESTRING:
  317.                 fprintf(file, "%s(%s)",GetMBString, code);
  318.                 MB_GetNextCode(&type, &code);
  319.                 IndentFunction = TRUE;
  320.                 if (InFunction)
  321.                 {
  322.                     if (type  != TC_END_FUNCTION)
  323.                         fprintf(file, ", ");
  324.                     IndentFunction = FALSE;
  325.                 }
  326.                 else
  327.                     fprintf(file, ",\n");
  328.                 break;
  329.  
  330.             case TC_LOCALECHAR:
  331.                 fprintf(file, "%s(%s)[0]",GetString, code);
  332.                 MB_GetNextCode(&type, &code);
  333.                 IndentFunction = TRUE;
  334.                 if (InFunction)
  335.                 {
  336.                     if (type  != TC_END_FUNCTION)
  337.                         fprintf(file, ", ");
  338.                     IndentFunction = FALSE;
  339.                 }
  340.                 else
  341.                     fprintf(file, ",\n");
  342.                 break;
  343.  
  344.             case TC_INTEGER:
  345.                 fprintf(file, "%s", code);
  346.                 MB_GetNextCode(&type, &code);
  347.                 IndentFunction = TRUE;
  348.                 if (InFunction)
  349.                 {
  350.                     if (type  != TC_END_FUNCTION)
  351.                         fprintf(file, ", ");
  352.                     IndentFunction = FALSE;
  353.                 }
  354.                 else
  355.                     fprintf(file, ",\n");
  356.                 break;
  357.  
  358.             case TC_CHAR:
  359.                 fprintf(file, "'%s'",code);
  360.                 MB_GetNextCode(&type, &code);
  361.                 IndentFunction = TRUE;
  362.                 if (InFunction)
  363.                 {
  364.                     if (type  != TC_END_FUNCTION)
  365.                         fprintf(file, ", ");
  366.                     IndentFunction = FALSE;
  367.                 }
  368.                 else
  369.                     fprintf(file, ",\n");
  370.                 break;
  371.  
  372.             case TC_VAR_AFFECT:
  373.                 name = atoi(code);
  374.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  375.                 if (type == TYPEVAR_LOCAL_PTR)
  376.                     fprintf( file, "\t%s = ", code);
  377.                 else
  378.                     fprintf(file, "\tObjectApp->%s = ", code);
  379.                 IndentFunction = FALSE;
  380.                 MB_GetNextCode(&type, &code);
  381.                 break;
  382.  
  383.             case TC_OBJ_ARG:
  384.             case TC_VAR_ARG:
  385.                 name = atoi(code);
  386.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  387.                 if (type == TYPEVAR_LOCAL_PTR)
  388.                     fprintf(file, "%s", code);
  389.                 else
  390.                     fprintf(file, "ObjectApp->%s", code);
  391.                 MB_GetNextCode(&type, &code);
  392.                 if ((InFunction)&&(type != TC_END_FUNCTION))
  393.                     fprintf(file, ", ");
  394.                 if (!InFunction)
  395.                 {
  396.                     fprintf(file, ",\n");
  397.                     IndentFunction = TRUE;
  398.                 }
  399.                 break;
  400.  
  401.             case TC_END_FUNCTION:
  402.                 MB_GetNextCode(&type, &code);
  403.                 if (nb_function>1)
  404.                 {
  405.                     if (type != TC_END_FUNCTION)
  406.                         fprintf(file, "),");
  407.                     else
  408.                         fprintf(file, ")");
  409.                 }
  410.                 else
  411.                 {
  412.                     if (obj_function)
  413.                         fprintf(file, ");\n\n");
  414.                     else
  415.                         fprintf(file, "),\n");
  416.                     IndentFunction = TRUE;
  417.                     InFunction     = FALSE;
  418.                     obj_function   = FALSE;
  419.                 }
  420.                 nb_function--;
  421.                 break;
  422.  
  423.             case TC_BOOL:
  424.                 if (*code == '0')
  425.                     fprintf(file, "FALSE");
  426.                 else
  427.                     fprintf(file, "TRUE" );
  428.                 MB_GetNextCode(&type, &code);
  429.                 if (InFunction)
  430.                 {
  431.                     if (type != TC_END_FUNCTION)
  432.                     {
  433.                         fprintf(file, ", ");
  434.                         IndentFunction = FALSE;
  435.                     }
  436.                 }
  437.                 else
  438.                     fprintf(file, ",\n");
  439.                 break;
  440.  
  441.             case TC_MUIARG:
  442.                 if (IndentFunction)
  443.                     Indent(file,nb_indent);
  444.                 name = atoi(code);
  445.                 fprintf(file, "%s", MUIStrings[name]);
  446.                 MB_GetNextCode(&type, &code);
  447.                 if (InFunction)
  448.                 {
  449.                     if (type != TC_END_FUNCTION)
  450.                     {
  451.                         fprintf(file, ", ");
  452.                         IndentFunction = FALSE;
  453.                     }
  454.                 }
  455.                 else
  456.                 {
  457.                     fprintf(file, ",\n");
  458.                     IndentFunction = TRUE;
  459.                 }
  460.                 break;
  461.  
  462.             case TC_MUIARG_ATTRIBUT:
  463.                 if (IndentFunction)
  464.                     Indent(file,nb_indent);
  465.                 name = atoi(code);
  466.                 MB_GetNextCode(&type, &code);
  467.                 if (InObj)
  468.                     fprintf(file, "%s,\n", MUIStrings[name]);
  469.                 else
  470.                 {
  471.                     if (InFunction)
  472.                     {
  473.                         if (type != TC_END_FUNCTION)
  474.                             fprintf(file, "%s,", MUIStrings[name]);
  475.                         else
  476.                             fprintf(file, "%s", MUIStrings[name]);
  477.                     }
  478.                     else
  479.                         fprintf(file, "%s;\n\n", MUIStrings[name]);
  480.                 }
  481.                 break;
  482.  
  483.             case TC_MUIARG_OBJ:
  484.                 if (IndentFunction)
  485.                     Indent(file,nb_indent);
  486.                 name = atoi(code);
  487.                 MB_GetNextCode(&type, &code);
  488.                 fprintf(file, "%s;\n\n", MUIStrings[name]);
  489.                 break;
  490.  
  491.             case TC_EXTERNAL_FUNCTION:
  492.                 fprintf(file, "&%sHook", code);
  493.                 MB_GetNextCode(&type, &code);
  494.                 if (InFunction)
  495.                 {
  496.                     if (type != TC_END_FUNCTION)
  497.                     {
  498.                         fprintf(file, ", ");
  499.                         IndentFunction = FALSE;
  500.                     }
  501.                 }
  502.                 else
  503.                 {
  504.                     fprintf(file, ",\n");
  505.                     IndentFunction = TRUE;
  506.                 }
  507.                 break;
  508.  
  509.             default:
  510.             {
  511.                 char    msg[80];
  512.  
  513.                 sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type);
  514.                 DisplayMsg(msg);
  515.             }
  516.             break;
  517.         }
  518.     }
  519. }
  520.  
  521. /****************************************************************************************************************/
  522. /*****                                                                                                        *****/
  523. /**                                                WriteNotify                                                        **/
  524. /*****                                                                                                        *****/
  525. /****************************************************************************************************************/
  526.  
  527. static void WriteNotify(FILE *file,char *GetString,char *GetMBString)
  528. {
  529.     ULONG    type;
  530.     char*    code;
  531.     int        name;
  532.     BOOL    indent = FALSE;
  533.  
  534.     fprintf(file, "\n");
  535.     MB_GetNextNotify(&type, &code);
  536.     while(type != -1)
  537.     {
  538.         if (indent)
  539.             fprintf(file, "\t\t");
  540.         indent = TRUE;
  541.         switch(type)
  542.         {
  543.             case TC_END_FUNCTION:
  544.             case TC_END_NOTIFICATION:
  545.                 fprintf(file, ");\n\n");
  546.                 MB_GetNextNotify(&type, &code);
  547.                 indent = FALSE;
  548.                 break;
  549.  
  550.             case TC_BEGIN_NOTIFICATION:
  551.                 name = atoi(code);
  552.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  553.                 if (type == TYPEVAR_LOCAL_PTR)
  554.                     fprintf(file, "\tDoMethod(%s,\n", code);
  555.                 else
  556.                     fprintf(file, "\tDoMethod(ObjectApp->%s,\n", code);
  557.                 MB_GetNextNotify(&type, &code);
  558.                 break;
  559.  
  560.             case TC_FUNCTION:
  561.                 name = atoi(code);
  562.                 fprintf(file, "\t%s(", MUIStrings[name]);
  563.                 MB_GetNextNotify(&type, &code);
  564.                 indent = FALSE;
  565.                 break;
  566.  
  567.             case TC_STRING:
  568.                 fprintf(file, "\"%s\"",code);
  569.                 MB_GetNextNotify(&type, &code);
  570.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  571.                     fprintf(file, ",\n");
  572.                 else
  573.                     fprintf(file, "\n");
  574.                 break;
  575.  
  576.             case TC_LOCALESTRING:
  577.                 fprintf(file, "%s(%s)",GetMBString, code);
  578.                 MB_GetNextNotify(&type, &code);
  579.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  580.                     fprintf(file, ",\n");
  581.                 else
  582.                     fprintf(file, "\n");
  583.                 break;
  584.  
  585.             case TC_LOCALECHAR:
  586.                 fprintf(file, "%s(%s)[0]",GetString, code);
  587.                 MB_GetNextNotify(&type, &code);
  588.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  589.                     fprintf(file, ",\n");
  590.                 else
  591.                     fprintf(file, "\n");
  592.                 break;
  593.  
  594.             case TC_INTEGER:
  595.                 fprintf(file, "%s", code);
  596.                 MB_GetNextNotify(&type, &code);
  597.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  598.                     fprintf(file, ",\n");
  599.                 else
  600.                     fprintf(file, "\n");
  601.                 break;
  602.  
  603.             case TC_CHAR:
  604.                 fprintf(file, "'%s'",code);
  605.                 MB_GetNextNotify(&type, &code);
  606.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  607.                     fprintf(file, ",\n");
  608.                 else
  609.                     fprintf(file, "\n");
  610.                 break;
  611.  
  612.             case TC_VAR_ARG:
  613.                 name = atoi(code);
  614.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  615.                 if ((type==TYPEVAR_LOCAL_PTR)||(type==TYPEVAR_EXTERNAL_PTR))
  616.                     fprintf(file, "%s", code);
  617.                 else
  618.                     fprintf(file, "ObjectApp->%s", code);
  619.                 MB_GetNextNotify(&type, &code);
  620.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  621.                     fprintf(file, ",\n");
  622.                 else
  623.                     fprintf(file, "\n");
  624.                 break;
  625.  
  626.             case TC_BOOL:
  627.                 if (*code == '0')
  628.                     fprintf(file, "FALSE");
  629.                 else
  630.                     fprintf(file, "TRUE" );
  631.                 MB_GetNextNotify(&type, &code);
  632.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  633.                     fprintf(file, ",\n");
  634.                 else
  635.                     fprintf(file, "\n");
  636.                 break;
  637.  
  638.             case TC_MUIARG:
  639.             case TC_MUIARG_OBJ:
  640.                 name = atoi(code);
  641.                 fprintf(file, "%s", MUIStrings[name]);
  642.                 MB_GetNextNotify(&type, &code);
  643.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  644.                     fprintf(file, ", ");
  645.                 indent = FALSE;
  646.                 break;
  647.  
  648.             case TC_MUIARG_ATTRIBUT:
  649.                 name = atoi(code);
  650.                 fprintf(file, "%s", MUIStrings[name]);
  651.                 MB_GetNextNotify(&type, &code);
  652.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  653.                     fprintf(file, ",\n");
  654.                 else
  655.                     fprintf(file, "\n");
  656.                 break;
  657.  
  658.             case TC_EXTERNAL_CONSTANT:
  659.                 fprintf(file, "%s", code);
  660.                 MB_GetNextNotify(&type, &code);
  661.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  662.                     fprintf(file, ",\n");
  663.                 else
  664.                     fprintf(file, "\n");
  665.                 break;
  666.  
  667.             case TC_EXTERNAL_FUNCTION:
  668.                 fprintf(file, "&%sHook", code);
  669.                 MB_GetNextNotify(&type, &code);
  670.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  671.                     fprintf(file, ",\n");
  672.                 else
  673.                     fprintf(file, "\n");
  674.                 break;
  675.  
  676.             case TC_EXTERNAL_VARIABLE:
  677.                 fprintf(file, "%s", code);
  678.                 MB_GetNextNotify(&type, &code);
  679.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  680.                     fprintf(file, ",\n");
  681.                 else
  682.                     fprintf(file, "\n");
  683.                 break;
  684.  
  685.             default:
  686.             {
  687.                 char msg[80];
  688.  
  689.                 sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type);
  690.                 DisplayMsg(msg);
  691.             }
  692.             break;
  693.         }
  694.     }
  695. }
  696.  
  697. /****************************************************************************************************************/
  698. /*****                                                                                                        *****/
  699. /**                                                 WriteHeaderFile                                                   **/
  700. /*****                                                                                                        *****/
  701. /****************************************************************************************************************/
  702.  
  703. void WriteHeaderFile(char *HeaderFile,char *HHeaderText,char *FileName,ULONG varnb,
  704.                      BOOL Env,BOOL Notifications,BOOL Locale)
  705. {
  706.     char    *name;
  707.     FILE    *file;
  708.  
  709.     file = fopenFile(HeaderFile, "w+", FALSE);
  710.     if (file)
  711.     {
  712.         fprintf(file,"#ifndef GUI_FILE_H\n");
  713.         fprintf(file,"#define GUI_FILE_H\n\n");
  714.         if (Env)
  715.             fprintf(file,"%s",HHeaderText);
  716.         if (Locale)
  717.             fprintf(file, "#include \"%s_cat.h\"\n\n",FilePart(FileName));
  718.         MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  719.         fprintf(file, "struct Obj%s\n{\n", name);
  720.         WriteDeclarations(file,varnb,TYPEVAR_PTR);
  721.         WriteDeclarations(file,varnb,TYPEVAR_BOOL);
  722.         WriteDeclarations(file,varnb,TYPEVAR_INT);
  723.         WriteDeclarations(file,varnb,TYPEVAR_STRING);
  724.         WriteDeclarations(file,varnb,TYPEVAR_TABSTRING);
  725.         fprintf(file,"};\n\n");
  726.         if (Notifications)
  727.         {
  728.             WriteDeclarations(file,varnb,TYPEVAR_IDENT);
  729.             fprintf(file, "\n");
  730.         }
  731.         if (Env)
  732.         {
  733.             fprintf(file,"extern struct Obj%s * Create%s(",name,name);
  734.             WriteParameters(file,varnb,Notifications);
  735.             fprintf(file,");\n");
  736.             fprintf(file,"extern void Dispose%s(struct Obj%s *);\n", name, name);
  737.         }
  738.         fprintf(file,"\n#endif\n");
  739.         fcloseFile(file);
  740.     }
  741.     else
  742.     {
  743.         DisplayMsg("Unable to create GUI Header file !!! \n");
  744.     }
  745. }
  746.  
  747. /****************************************************************************************************************/
  748. /*****                                                                                                        *****/
  749. /**                                             WriteGUIFile                                                       **/
  750. /*****                                                                                                        *****/
  751. /****************************************************************************************************************/
  752.  
  753. void WriteGUIFile(char *MBDir,char *HeaderFile,char *GUIFile,char *CHeaderText,
  754.                   char *Externals,char *GetString,char *GetMBString,
  755.                   ULONG varnb,
  756.                   BOOL ExternalExist,BOOL Env,BOOL Locale,BOOL Declarations,BOOL Code,BOOL Notifications)
  757. {
  758.     char    *name;
  759.     FILE    *file;
  760.     char    *FromHookfile;
  761.     char    *ToHookfile;
  762.     int        i;
  763.     ULONG    type,length;
  764.     BOOL    HookExist;
  765.  
  766.     if (file = fopenFile(GUIFile, "w+",FALSE))
  767.     {
  768.         if (Env)
  769.         {
  770.             fprintf(file,"%s",CHeaderText);
  771.             MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  772.             fprintf(file, "\n#include \"%s\"\n", FilePart(HeaderFile));
  773.             if (ExternalExist)
  774.                 fprintf(file, "#include \"%s\"\n", FilePart(Externals));
  775.             for(i = 0, HookExist = FALSE; !HookExist && i<varnb;i++)
  776.             {
  777.                 MB_GetVarInfo (i,MUIB_VarType, &type, TAG_END);
  778.                 HookExist = (type == TYPEVAR_HOOK);
  779.             }
  780.             if (HookExist)
  781.             {
  782.                 fprintf(file, "#include \"Hook_utility.h\"");
  783.  
  784.                 /* Copy Utility_Hook.h in current directory */
  785.                 FromHookfile=AllocMemory(strlen(MBDir)+14+2,TRUE);
  786.                 strcpy(FromHookfile,MBDir);
  787.                 AddPart(FromHookfile,"Hook_utility.h",strlen(MBDir)+14+2);
  788.  
  789.                 length = (long)FilePart(GUIFile)-(long)GUIFile;
  790.                 ToHookfile=AllocMemory(length+14+2,TRUE);
  791.                 strncpy(ToHookfile,GUIFile,length);
  792.                 ToHookfile[length]='\0';
  793.                 AddPart(ToHookfile,"Hook_utility.h",length+14+2);
  794.  
  795.                 if (!(CopyFile(FromHookfile,ToHookfile)))
  796.                 {
  797.                     DisplayMsg("Can't copy Hook_utility.h in your source directory !!!");
  798.                 }
  799.  
  800.                 /* Copy Hook_utility.o in current directory */
  801.                 strcpy(FromHookfile,MBDir);
  802.                 AddPart(FromHookfile,"Hook_utility.o",strlen(MBDir)+14+2);
  803.  
  804.                 strncpy(ToHookfile,GUIFile,length);
  805.                 ToHookfile[length]='\0';
  806.                 AddPart(ToHookfile,"Hook_utility.o",length+14+2);
  807.  
  808.                 if (!(CopyFile(FromHookfile,ToHookfile)))
  809.                 {
  810.                     DisplayMsg("Can't copy Hook_utility.o in your source directory !!!");
  811.                 }
  812.  
  813.                 FreeMemory(FromHookfile);
  814.                 FreeMemory(ToHookfile);
  815.             }
  816.             if (Locale)
  817.               {
  818.                 fprintf(file, "\nstatic char *%s(APTR ref)\n{\n", GetMBString);
  819.                 fprintf(file, "\tchar *aux;\n\n");
  820.                 fprintf(file, "\taux = %s(ref);\n", GetString);
  821.                 fprintf(file, "\tif (aux[1] == '\\0') return(&aux[2]);\n");
  822.                 fprintf(file, "\telse                return(aux);\n}\n");
  823.               }
  824.             fprintf(file, "\nstruct Obj%s * Create%s(", name, name);
  825.             WriteParameters(file,varnb,Notifications);
  826.             fprintf(file, ")\n");
  827.             fprintf(file, "{\n\tstruct Obj%s * ObjectApp;\n\n", name);
  828.         }
  829.         if (Declarations)
  830.         {
  831.             WriteDeclarations(file,varnb,TYPEVAR_LOCAL_PTR);
  832.             if (HookExist)
  833.                 WriteDeclarations(file,varnb,TYPEVAR_HOOK);
  834.         }
  835.         if (Env)
  836.             fprintf(file, "\n\tif (!(ObjectApp = AllocVec(sizeof(struct Obj%s),MEMF_CLEAR)))\n\t\treturn(NULL);\n\n", name);
  837.         if (Declarations)
  838.         {
  839.             WriteInitialisations(file,varnb,TYPEVAR_STRING,Locale,GetMBString);
  840.             WriteInitialisations(file,varnb,TYPEVAR_TABSTRING,Locale,GetMBString);
  841.             if (HookExist)
  842.                 WriteInitialisations(file,varnb,TYPEVAR_HOOK,Locale,GetMBString);
  843.         }
  844.         if (Code)
  845.             WriteCode(file,GetString,GetMBString);
  846.         if (Env)
  847.         {
  848.             fprintf(file, "\n\tif (!ObjectApp->%s)\n\t{\n\t\tFreeVec(ObjectApp);", name);
  849.             fprintf(file, "\n\t\treturn(NULL);\n\t}\n");
  850.         }
  851.         if (Notifications)
  852.             WriteNotify(file,GetString,GetMBString);
  853.         if (Env)
  854.         {
  855.             fprintf(file, "\n\treturn(ObjectApp);\n}\n");
  856.             fprintf(file, "\nvoid Dispose%s(struct Obj%s * ObjectApp)\n{\n", name, name);
  857.             fprintf(file, "\tMUI_DisposeObject(ObjectApp->%s);\n", name);
  858.             fprintf(file, "\tFreeVec(ObjectApp);\n}\n");
  859.         }
  860.         fcloseFile(file);
  861.     }
  862.     else
  863.     {
  864.         DisplayMsg("Unable to create GUI file !!!\n");
  865.     }
  866. }
  867.